<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
	</head>

	<body erke-hide>
	</body>
	<script>
	 /**
 * @param {number[][]} grid
 * @return {number}
 */
var numMagicSquaresInside = function(grid) {
	if(grid.length<3&&grid[0].length<3){
		return 0;
	};
	var count=0;
    for(var i=0;i<grid.length-2;i++){
    	for(var j=0;j<grid[i].length-2;j++){
    		if(aAronDie(grid,i,j)){
    			console.log([i,j]);
    			count++;
    		};
    	};
    };
    return count;
};
function aAronDie(grid,i,j){
	var res=grid[i][j]+grid[i][j+1]+grid[i][j+2];
	for(var a=0;a<3;a++){
		for(var b=0;b<3;b++){
			if(grid[i+a][j+b]==0||grid[i+a][j+b]>9){
				return false;
			};
		};
	};
	return res==grid[i+1][j]+grid[i+1][j+1]+grid[i+1][j+2]&&res==grid[i+2][j]+grid[i+2][j+1]+grid[i+2][j+2]&&res==grid[i][j]+grid[i+1][j]+grid[i+2][j]&&res==grid[i][j]+grid[i][j+1]+grid[i][j+2]&&res==grid[i+1][j]+grid[i+1][j+1]+grid[i+1][j+2]&&res==grid[i+2][j]+grid[i+2][j+1]+grid[i+2][j+2]&&res==grid[i][j]+grid[i+1][j+1]+grid[i+2][j+2]&&res==grid[i][j+2]+grid[i+1][j+1]+grid[i+2][j];
};
res = new numMagicSquaresInside([[7,0,5],[2,4,6],[3,8,1]]);
</script>

</html>